//
//  FindViewController.m
//  ToYourHeartNews
//
//  Created by XJing on 16/1/22.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "FindViewController.h"
#import "AfNetWorkingHandler.h"
#import "FindsModel.h"
#import "FindDetailCell.h"
#import "FindDetailModel.h"
#import <UIImageView+WebCache.h>
#import "PushWebViewVC.h"
@interface FindViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *findArr;
@end

@implementation FindViewController
- (void)dealloc
{
    [_path release];
    [_titleName release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    self.navigationItem.title = _titleName;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-newlisticon06"] style:UIBarButtonItemStylePlain target:self action:@selector(fanhui)];
    [_tableView registerClass:[FindDetailCell class] forCellReuseIdentifier:@"Findcell"];
    [self.view addSubview:_tableView];
    //数据处理
    [self dataHandler];
}
-(void)fanhui
{
    [self dismissViewControllerAnimated:YES completion:^{
        //
    }];
}
//数据处理
-(void)dataHandler
{
    [AfNetWorkingHandler GetWithStr:_path complection:^(id result) {
        //
        NSArray *arr = result[@"data"][@"posts"];
        self.findArr = [FindDetailModel modelHanderWithArray:arr];
        [_tableView reloadData];
    }];
}
//点击进入详情webView
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PushWebViewVC *detailVC = [[PushWebViewVC alloc]init];
    FindDetailModel *m = _findArr[indexPath.row];
    detailVC.pathstr = m.weburl;
    [self.navigationController pushViewController:detailVC animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 400;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _findArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FindDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Findcell" forIndexPath:indexPath];
    FindDetailModel *m = _findArr[indexPath.row];
    [cell.userImg sd_setImageWithURL:[NSURL URLWithString:m.autherImg]];
    cell.userLable.text = m.autherName;
    cell.timeLable.text = m.date;
    cell.contentLable.text = m.content;
    [cell.picture sd_setImageWithURL:[NSURL URLWithString:m.imgPath]];
    cell.hotLabel.text = m.hot_num;
    cell.likeLable.text = m.like_num;
    cell.messageLable.text = m.comment_count;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
